//
//  SEGCatchCrash.m
//  ExcellentHome
//
//  Created by 刘山 on 2017/12/20.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGCatchCrash.h"
#import "SEGIAnalyticsLogErrorModel.h"
#import "SEGIAnalyticsComm.h"
#import "SEGIAnalyticsLogErrorDBManager.h"

@implementation SEGCatchCrash
void uncaughtExceptionHandler(NSException *exception)
{
    NSString *reason = [exception reason];
    NSArray *stackArray = [exception callStackSymbols];
    NSString *exceptionInfo = [NSString stringWithFormat:@"%@", stackArray];
    exceptionInfo = [stackArray componentsJoinedByString:@","];
    
    SEGIAnalyticsLogErrorModel *data = [SEGIAnalyticsLogErrorModel new];
    data.pf = kBundleIdentifier;
    data.id = [SEGIAnalyticsComm segSessionCode];
    data.dvcCode = [SEGIAnalyticsComm uuid];
    data.dvcType = [SEGIAnalyticsComm segDeviceModel];
    data.dvcBrd = SEGDeviceBrandApple;
    data.dvcVer = [SEGIAnalyticsComm segMachineModelName];
    data.dvcSys = [SEGIAnalyticsComm segDeviceSystemName];
    data.dvcSysVer = [SEGIAnalyticsComm segDeviceSystemVersion];
    data.pfVer = kAppVersion;
    data.network = [SEGIAnalyticsComm segDeviceNetworkStatus];
    data.createTime = [SEGIAnalyticsComm segCurrentTimeStamp];
    data.digest = reason;
    data.stacktrace = exceptionInfo;
    
    [SEGIAnalyticsLogErrorDBManager segLogErrorInsertWithData:data];
}
@end
